(function (gdg) {
    'use strict';

    function GuessNumber() {
        var self = this;
        self.reset = function () {
            self.answer = Math.floor(Math.random() * 100);
            if (!self.histories) {
                self.histories = [];
            }
            if (self.histories.length > 0) {
                self.histories.splice(0, self.histories.length);
            }
        };
        self.check = function (value) {
            var val = parseInt(value, 10),
                item = {
                    value: value,
                    message: "n/a"
                };
            self.histories.splice(0, 0, item);
            if (!isNaN(val)) {
                if (val === self.answer) {
                    item.message = "You got it";
                    return true;
                } else {
                    if (val < self.answer) {
                        item.message = "you're small";
                    } else {
                        item.message = "you're big";
                    }
                }
            }
            return false;
        };
        self.reset();
    }

    gdg.GuessNumber = GuessNumber;
})(window.gdg || (window.gdg = {}));